<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

  protected function _initAppAutoload() {
    $moduleLoad = new Zend_Application_Module_Autoloader(array(
                'namespace' => '',
                'basePath' => APPLICATION_PATH
            ));
  }

  protected function _initDoctrine() {
    $this->getApplication()->getAutoloader()
            ->pushAutoloader(array('Doctrine', 'autoload'));
    spl_autoload_register(array('Doctrine', 'modelsAutoload'));

    $doctrineConfig = $this->getOption('doctrine');

    $manager = Doctrine_Manager::getInstance();
    $manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
    $manager->setAttribute(
            Doctrine::ATTR_MODEL_LOADING,
            $doctrineConfig['model_autoloading']
    );
    //$manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);
    $manager->setCharset('UTF8');
    $manager->setCollate('utf8_general_ci');

    $doctrineConfig = $this->getOption('doctrine');
    Doctrine::loadModels($doctrineConfig['models_path']);
    $conn = Doctrine_Manager::connection($doctrineConfig['dsn'], 'doctrine');
    $conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true);
    $conn->setCharset('UTF8');

    return $conn;
  }

  protected function _initActionHelper() {
    $writer = new Zend_Log_Writer_Firebug();
    $logger = new Zend_Log($writer);
    Zend_Registry::set('logger', $logger);
    return $logger;
  }

  protected function _initView(){
    $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
    $viewRenderer->setView($this->getView());
    ZendX_JQuery::enableView($this->getView());
    ZT_CodaSlider::enableView($this->getView());
    $this->getView()->doctype('XHTML1_STRICT');
  }

  private function getView() {
    if (null === $this->_view) {
      $this->_view = new Zend_View();
    }
    return $this->_view;
  }

}

